package com.ruoyi.web.controller;

import cn.hutool.core.date.DateUtil;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.system.domain.po.*;
import com.ruoyi.system.service.PetHospitalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

@RestController
@RequestMapping("/petHospitalController")
public class PetHospitalController extends BaseController {

    @Autowired
    private PetHospitalService petHospitalService;

    /**
     * 挂号就诊
     *
     * @param consultationPO 就诊信息
     * @return 挂号结果
     */
    @PostMapping("/consultation")
    public AjaxResult consultation(@Validated @RequestBody ConsultationPO consultationPO) {
        return petHospitalService.consultation(consultationPO);
    }

    /**
     * 根据手机号查询客户信息
     *
     * @param phone 手机号
     * @return 客户信息
     */
    @GetMapping("/queryCustomerByPhone")
    public AjaxResult queryCustomerByPhone(@RequestParam(value = "phone") String phone) {
        return petHospitalService.queryCustomerByPhone(phone);
    }

    /**
     * 会员充值
     *
     * @param customerRechargePO 充值信息
     * @return 会员充值
     */
    @PostMapping("/recharge")
    public AjaxResult recharge(@Validated @RequestBody CustomerRechargePO customerRechargePO) {
        return petHospitalService.recharge(customerRechargePO);
    }

    /**
     * 根据医生查询就诊宠物信息
     *
     * @param consultationRecordPO 手机号
     * @return 客户信息
     */
    @PostMapping("/queryConsultationRecord")
    public TableDataInfo queryConsultationRecord(@RequestBody ConsultationRecordPO consultationRecordPO) {
        startPage();
        return getDataTable(petHospitalService.queryConsultationRecord(consultationRecordPO));
    }

    /**
     * 开处方
     *
     * @param prescriptionPO 处方信息
     * @return 客户信息
     */
    @PostMapping("/prescribing")
    public AjaxResult prescribing(@Validated @RequestBody ConsultationPrescriptionPO prescriptionPO) {
        return petHospitalService.prescribing(prescriptionPO);
    }

    /**
     * 缓存就诊单开处方
     *
     * @param prescriptionPO 处方信息
     * @return 客户信息
     */
    @PostMapping("/prescribingCache")
    public AjaxResult prescribingCache(@Validated @RequestBody ConsultationPrescriptionPO prescriptionPO) {
        return petHospitalService.prescribingCache(prescriptionPO);
    }

    /**
     * 获取缓存就诊单开处方
     *
     * @param consultationId 处方信息
     * @return 客户信息
     */
    @GetMapping("/getPrescribingCache")
    public AjaxResult getPrescribingCache(@RequestParam("consultationId") Long consultationId) {
        return petHospitalService.getPrescribingCache(consultationId);
    }

    /**
     * 检查
     *
     * @param prescriptionPO 处方信息
     * @return 客户信息
     */
    @PostMapping("/inspection")
    public AjaxResult inspection(@Validated @RequestBody InspectionRecordPO prescriptionPO) {
        if (prescriptionPO.getId() == null) {
            return AjaxResult.error("id不能为空");
        }
        return petHospitalService.inspection(prescriptionPO);
    }

    /**
     * 零售
     *
     * @param retailPO 零售
     * @return 零售
     */
    @PostMapping("/retail")
    public AjaxResult retail(@Validated @RequestBody RetailPO retailPO) {
        return petHospitalService.retail(retailPO);
    }

    /**
     * 查询待出库的出库单
     *
     * @param customerPhone 手机号
     * @return 出库单
     */
    @GetMapping("/queryOutboundOrder")
    public AjaxResult queryOutboundOrder(String customerPhone, Date timeStart, Date timeEnd) {
        return petHospitalService.queryOutboundOrder(customerPhone, timeStart, timeEnd);
    }

    /**
     * 处方出库
     *
     * @param inspectionOutboundPO 处方
     * @return 处方出库
     */
    @PostMapping("/outbound")
    public AjaxResult outbound(@Validated @RequestBody InspectionOutboundPO inspectionOutboundPO) {
        return petHospitalService.outbound(inspectionOutboundPO);
    }

}
